-
-
Notifications
You must be signed in to change notification settings - Fork 195
LONDON| MAY 2025 | HAKAN MURAT KAVUT | Module-Structuring-and-Testing-Data - Sprint 3 #611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
PASS Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js Test Suites: 7 passed, 7 total |
if (angle < 90) return "Acute angle"; | ||
if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
if (angle > 180 && angle < 360) return "Reflex angle"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec isn't clear whether angle
can be assigned a number not in the interval (0, 360).
When angle
is >= 360, what should the function return? (Also, by definition, angles <= 0 are not considered acute angles.)
When we implement a function that can return a value, to ensure reliability, we should ensure it will always return a defined value instead of undefined
(which represents "no return value").
If the parameter, angle
, is not within the recognised range, we can design the function to return a special value (e.g., "Invalid angle") or throw an error.
if (Math.abs(numerator) < Math.abs(denominator)) return true; | ||
if (Math.abs(numerator) > Math.abs(denominator)) return true; | ||
if (Math.abs(numerator) === Math.abs(denominator)) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In mathematics, -A/B == A/-B == -(A/B), and -A/-B == A/B for any integers A and B (B ≠ 0).
They represent a proper fraction if A < B and A ≠ 0 and B ≠ 0.
The function is supposed to return true
only when numerator/denominator represent a proper fraction.
@@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => { | |||
}); | |||
|
|||
// Case 2: Identify Improper Fractions: | |||
test("should return true for a improper fraction", () => { | |||
expect(isProperFraction(5, 2)).toEqual(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Identify improper fractions" means, "should return false
for a improper fraction"
test("should return true for a equal fraction", () => { | ||
expect(isProperFraction(3, 3)).toEqual(true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3/3 is an improper fraction, so the function is expected to return false
.
@@ -1,5 +1,8 @@ | |||
function getCardValue(card) { | |||
// replace with your code from key-implement | |||
return 11; | |||
let rank = card[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
card[0]
only refers to the first character.
return "hellohellohello"; | ||
function repeat(str, count) { | ||
|
||
if (Number(count) > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you explicitly convert count
to a number? Isn't count
already a number?
} | ||
if (count == 1) return str; | ||
if (count == 0) return ""; | ||
return "Negative counts are not valid."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would the caller distinguish the result of the following two function calls?
repeat("Negative counts are not valid.", 1)
repeat("", -1)
Both function calls return the same value.
test("should repeat empty string for count equals zero", () => { | ||
const str = "hello"; | ||
const count = -5; | ||
const repeatedStr = repeat(str, count); | ||
expect(repeatedStr).toEqual("Negative counts are not valid."); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you modified repeat()
to throw an error when count
is negative, and you wanted to test if the function can throw an error as expected, you can use .toThrow()
. You can find out more about how to use .toThrow()
here: https://jestjs.io/docs/expect#tothrowerror (Note: Pay close attention to the syntax of the example)
let numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; | ||
|
||
// Build alphabet arrays manually | ||
let smallLetters = []; | ||
let upperLetters = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String also have includes()
method which can be used to check if a character is one of the characters in the string.
We could also prepare numbers
, smallLetters
as
// Declaring them using const can prevent them from being accidently reassigned a different value.
const numbers = "0123456789";
const smallLetters = "abcdefghijklmnopqrstuvwxyz";
test("password has not number", () => { | ||
// Arrange | ||
const password = "HELLOWORLD#"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function can return false
for multiple reasons.
To test a specific reason, choose an input that satisfies all other conditions except the one you're targeting. This way, if the function returns false
, you can confidently attribute it to that specific condition.
For example, the function might return false
for "HELLOWORLD#" not only because it lacks a digit, but also because it lacks a lowercase letter.
As a result, we can't be certain that the function correctly handles the case described in the test since multiple conditions are being violated simultaneously.
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.